<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
if($_RQ['op']=='main'){
	$return['params']=array('daytype'=>0);
	$return['orderparams']=array('daytype'=>0);
	$return['list']=array();
	exi($return);
}
if($_RQ['op']=='getlist'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	$return['params']=array();
	//创建时间
	if($_RQ['tstart'] && $_RQ['tend']){
		$params['successtime between']=array($_RQ['tstart'],$_RQ['tend']);
	}else{
		$daytype=intval($_RQ['daytype']);
		if($daytype==0){
			$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
			$params['successtime']=0;
		}elseif($daytype==1){
			$yesdaytime = mktime(0,0,0,date('m'),date('d')-1,date('Y'));
			$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
			$params['successtime between']=array($yesdaytime,$daytime);
		}elseif($daytype=2){
			$day7time = mktime(0,0,0,date('m'),date('d')-7,date('Y'));
			$params['successtime >']=$day7time;
		}elseif($daytype==3){
			$monthtime = strtotime(date('Y-m',time()));
			$params['successtime >']=$monthtime;
		}elseif($daytype==4){
			$monthtime=strtotime(date('Y-m',time()));
			$startmonthtime = strtotime(date('Y-m',$monthtime-2*24*3600));
			$params['successtime between']=array($startmonthtime,$monthtime);
		}elseif($daytype==5){
			
		}
	}
	$return['list']=pdo_getall('jy_nongfee_cang',$params);
	foreach($return['list'] as &$item){
		$item=model('jy_nongfee/model')->up_canginfo($item);
		$params=array('merchid'=>$merchid,'cangid'=>$item['id'],'uniacid'=>$_SESSION['uniacid']);
		$params1=$params;
		$item['jifen']=pdo_getsum('jy_nongfee_canlog',$params1,'jifen');
		$params2=$params;
		$params2['type']=array(0,1,3,5,6);
		$item['getjifen']=pdo_count('jy_nongfee_feelog',$params2,'fee');
		$params3=$params;
		$item['tonum']=pdo_count('jy_nongfee_canlog',$params3,'id');
		$params4=$params;
		$item['tousers']=pdo_count('jy_nongfee_canlog',$params4,'id');
	}
	exi($return);
}
if($_RQ['op']=='getorderlist'){
	$params=array('merchid'=>$merchid,'uniacid'=>$_SESSION['uniacid']);
	$return['params']=array();
	//创建时间
	if($_RQ['tstart'] && $_RQ['tend']){
		$params['createtime between']=array($_RQ['tstart'],$_RQ['tend']);
	}else{
		$daytype=intval($_RQ['daytype']);
		if($daytype==0){
			$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
			$params['createtime >']=$daytime;
		}elseif($daytype==1){
			$yesdaytime = mktime(0,0,0,date('m'),date('d')-1,date('Y'));
			$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
			$params['createtime between']=array($yesdaytime,$daytime);
		}elseif($daytype=2){
			$day7time = mktime(0,0,0,date('m'),date('d')-7,date('Y'));
			$params['createtime >']=$day7time;
			file_put_contents(ROOT_D.'/1.txt',$day7time);
		}elseif($daytype==3){
			$monthtime = strtotime(date('Y-m',time()));
			$params['createtime >']=$monthtime;
		}elseif($daytype==4){
			$monthtime=strtotime(date('Y-m',time()));
			$startmonthtime = strtotime(date('Y-m',$monthtime-2*24*3600));
			$params['createtime between']=array($startmonthtime,$monthtime);
		}elseif($daytype==5){
			
		}
	}
	$list=array();
	$params0=$params;
	$list[0]=array(
		'title'=>'总积分(个)',
		'num'=>pdo_getsum('jy_nongfee_canlog',$params0,'jifen')?:0.00,
	);
	$params1=$params;
	$params1['type']=array(0,1,3,5,6);
	$list[1]=array(
		'title'=>'总收益(个)',
		'num'=>pdo_getsum('jy_nongfee_feelog',$params1,'fee')?:0.00,
	);
	$params2=$params;
	$list[2]=array(
		'title'=>'总投入笔数(比)',
		'num'=>pdo_count('jy_nongfee_canlog',$params2,'id'),
	);
	$params3=$params;
	$list[3]=array(
		'title'=>'投入总人数(人)',
		'num'=>pdo_count('jy_nongfee_canlog',$params3,'id')?:0.00,
	);
	$return['list']=$list;
	exi($return);
}